package org.vectrics.graphics;

import org.vectrics.SystemException;
import org.vectrics.common.util.StringUtils;
import org.vectrics.struts.VectricsTagSupport;

/**
 * @author mmoore
 */
public class DynaGraphicFormButtonTag extends VectricsTagSupport {

	private static final long serialVersionUID = 5330180672130690609L;
	
	//<input type="image" src="//www.ibm.com/i/v11/m/en/search.gif" width="64" height="23" border="0" value="Search" name="Search" alt="Search" id="Search" />    
    private String code = null;
    private String value = null;
    private String name = null;
    private String caption = null;
    private String phraseCode = null;
    private String elementId = null;

    /**
     * 
     */
    public DynaGraphicFormButtonTag() {
        super();
    }

    protected String makeStartTag() {
        if (name == null)
            name = value;
        if (value == null)
            value = name;
        
        String captionText = null;
        if (phraseCode != null) {
            captionText = this.getPhrase(phraseCode);
            if (captionText == null)
                throw new SystemException("Could not find phrase code for button, phrase code = " + phraseCode);
        } else { 
            captionText = this.caption;
        }
        
        StringBuffer html = new StringBuffer();
        html.append("<input type=\"image\" ");
        
        String imageSource = this.getContextPath() + "/dynagraphic/button.jpg?code=" + code 
        	+ "&caption=" + captionText;
 

        html.append("src=\"");
        html.append(imageSource);
        html.append("\" border=\"0\" ");
        html.append("value=\"");
        html.append(value);
        html.append("\" ");
        html.append("name=\"");
        html.append(name);
        html.append("\" ");

        if (StringUtils.isNullOrBlank(this.getElementId()) == false) {
	        html.append("id=\"");
	        html.append(this.getElementId());
	        html.append("\" ");
        }
        
        html.append("/>");
        
        return(html.toString());
    }

    
    
    /**
     * @return Returns the caption.
     */
    public String getCaption() {
        return caption;
    }
    /**
     * @param caption The caption to set.
     */
    public void setCaption(String caption) {
        this.caption = caption;
    }
    /**
     * @return Returns the code.
     */
    public String getCode() {
        return code;
    }
    /**
     * @param code The code to set.
     */
    public void setCode(String code) {
        this.code = code;
    }
    /**
     * @return Returns the name.
     */
    public String getName() {
        return name;
    }
    /**
     * @param name The name to set.
     */
    public void setName(String name) {
        this.name = name;
    }
    /**
     * @return Returns the value.
     */
    public String getValue() {
        return value;
    }
    /**
     * @param value The value to set.
     */
    public void setValue(String value) {
        this.value = value;
    }
    
    
    /**
     * @return Returns the phraseCode.
     */
    public String getPhraseCode() {
        return phraseCode;
    }
    /**
     * @param phraseCode The phraseCode to set.
     */
    public void setPhraseCode(String phraseCode) {
        this.phraseCode = phraseCode;
    }

	public String getElementId() {
		return elementId;
	}

	public void setElementId(String elementId) {
		this.elementId = elementId;
	}
    
    
}
